<template>
  <div id="box">
    <el-container>
      <el-main>
        <el-header>注册信息</el-header>
        <div style="width: 400px;margin: auto">
          <el-form ref="form" :model="form" label-width="80px">
            <el-form-item label="用户名">
              <el-input v-model="form.username" placeholder="请输入用户名"></el-input>
            </el-form-item>
            <el-form-item label="密码">
              <el-input v-model="form.password" placeholder="请输入密码" type="password"></el-input>
            </el-form-item>
            <el-form-item label="类型">
              <el-input v-model="form.type" placeholder="请输入类型"></el-input>
            </el-form-item>
            <el-form-item label="电话">
              <el-input v-model="form.telephone" placeholder="请输入电话号码"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" style="background-color: green; color: #fff;" @click="onSubmit">确认注册</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-main>
    </el-container>
  </div>
</template>

<style>
.el-container {
  background-image: url('../../image/4.jpg'); /* 添加背景图片 */
  background-size: cover; /* 覆盖整个背景 */
  background-position: center; /* 居中显示 */
  height: 100vh;
  margin: 0;
}
.el-header {
  background-color:transparent;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-main {
  background-color: #E9EEF3;
  color: #333;
  text-align: center;
  line-height: 160px;
  height: 1000px;
  background-image: url('../../image/4.jpg'); /* 添加背景图片 */
  background-size: cover; /* 覆盖整个背景 */
  background-position: center; /* 居中显示 */
}
</style>
<script>
import axios from "axios";

export default {
  data() {
    return {
      form: {
        username: '',
        password: '',
        type: '管理员',
        telephone: ''
      }
    }
  },
  methods: {
    onSubmit() {
      axios.post('/api/register',this.form).then(res => {
        this.$message.success(res.data.msg || '注册成功');
      }).catch(err => {
        this.$message.error(err.data.msg || '注册失败，请联系管理员');
      })
      //跳转到登录界面
      this.$router.push({name: 'login'})
    }
  }
}
</script>
